package com.telsoft.hms.data;

import java.util.ArrayList;
import java.util.List;

import com.telsoft.hms.entity.ETT_Language;
import com.telsoft.hms.lib.admin.client.data.ClientDataPreprocessor;

/**
 * 
 * @author VIETPH
 *
 */
public class HMS_Language_DATA extends ClientDataPreprocessor {

	public List<ETT_Language> getListLanguage(String hospitalKey,
			int languageCode) throws Exception {
		List<ETT_Language> lLanguage = new ArrayList<>();
		StringBuilder sbSql = new StringBuilder(
				"SELECT lcf.LANGUAGE_CODE, lcf.IS_DEFAULT, lcf.IS_INTERNAL, "
						+ "lcv.SHORT_DISPLAY, lcv.DISPLAY_VALUE, lcf.STATUS, lcv.DESCRIPTION "
						+ "FROM LANGUAGE_CODE_REF lcf JOIN LANGUAGE_CODE_VALUES lcv ON lcf.LANGUAGE_CODE = lcv.LANGUAGE_CODE");
		try {
			open(hospitalKey);
			if (languageCode != 0) {
				sbSql.append(" WHERE lcv.INPUT_LANGUAGE != " + languageCode + " AND lcf.LANGUAGE_CODE = " + languageCode);
			}
			else{
				sbSql.append(" WHERE IS_DEFAULT=1");
			}
			mStmt = mConnection.prepareStatement(sbSql.toString());
			mRs = mStmt.executeQuery();
			while (mRs.next()) {
				ETT_Language language = new ETT_Language();
				language.setLanguageCode(mRs.getInt("LANGUAGE_CODE"));
				language.setIsDefault(mRs.getString("IS_DEFAULT"));
				language.setShortDisplay(mRs.getString("SHORT_DISPLAY"));
				language.setDisplayValue(mRs.getString("DISPLAY_VALUE"));
				language.setStatus(mRs.getString("STATUS"));
				language.setDescription(mRs.getString("DESCRIPTION"));

				lLanguage.add(language);
			}
		} finally {
			close(mConnection, mStmt, mRs);
		}
		return lLanguage;
	}

}
